import {
  CollectionViewer,
  DataSource,
  SelectionChange,
  SelectionModel,
} from '@angular/cdk/collections';
import { FlatTreeControl, TreeControl } from '@angular/cdk/tree';
import { Component, OnInit } from '@angular/core';
import { FormBuilder } from '@angular/forms';
import { Router } from '@angular/router';
import { NzMessageService } from 'ng-zorro-antd/message';
import { NzTreeFlattener, NzTreeFlatDataSource } from 'ng-zorro-antd/tree-view';
import { Observable, of, BehaviorSubject, merge } from 'rxjs';
import { tap, map } from 'rxjs/operators';
import { EmployeeService, OrganizationService } from 'sparrow-permission-lib';
import { FlatNode } from 'src/app/domain/flat-node';
import { Employee, Role } from 'src/app/domain/sparrow';
import { DynamicDataSourceForNzTreeService } from 'src/app/service/dynamic-data-source-for-nz-tree.service';
import { NzTreeCommonService } from 'src/app/service/nz-tree-common.service';
import { NzTreeGetChildren } from 'src/app/service/nz-tree-get-children';
import { NzTreeGetEmployeeChildrenService } from 'src/app/service/nz-tree-get-employee-children.service';

@Component({
  selector: 'app-employee-search',
  templateUrl: './employee-search.component.html',
  styleUrls: ['./employee-search.component.css'],
})
export class EmployeeSearchComponent implements OnInit {
  constructor(
    private message: NzMessageService,
    private employeeService: EmployeeService,
    private orgService: OrganizationService,
  ) { }

  treeService: NzTreeCommonService = new NzTreeCommonService();
  dataSource: any;
  hasChild = (_: number, node: FlatNode) => node.expandable;

  ngOnInit(): void {
  }

   // for permission
   optionList: any[] = [];
   selectedUser?: any[];
   isLoading = false;

   onSearch(value: string): void {
     this.isLoading = true;
     this.employeeService
       .all6({ page: 0, size: 100 }, value === '' ? undefined : { name: value })
       .subscribe((res) => {
         this.optionList = res.content!;
         this.isLoading = false;
       });
   }

}
